package com.bupt.ilink.mapper;

import com.bupt.ilink.entity.DatasetTags;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author zhangbo
 * @description 针对表【dataset_tags】的数据库操作Mapper
 * @createDate 2024-07-25 17:53:59
 * @Entity generator.domain.DatasetTags
 */
@Mapper
public interface DatasetTagsMapper extends BaseMapper<DatasetTags> {
    //    返回所有数据集标签
    @Select("SELECT * FROM dataset_tags WHERE dataset_id IN (SELECT distinct dataset_id FROM dataset_metadata WHERE access_level = 'public')")
    List<DatasetTags> getPublicDatasetTags();

    //    根据关键词查询
    @Select("SELECT * FROM dataset_tags WHERE dataset_id IN (SELECT dataset_id FROM dataset_metadata WHERE access_level = 'public' AND name LIKE CONCAT('%', #{keywords}, '%'))")
    List<DatasetTags> selectByKeywords(String keywords);

    //    根据标签查询
    @Select("SELECT * FROM dataset_tags WHERE tag = #{tag} ")
    List<DatasetTags> selectByTags(String tag);

    @Select("SELECT * FROM dataset_tags WHERE dataset_id = #{datasetId}")
    List<DatasetTags> selectByDatasetId(Long datasetId);

    //  查询标签种类
    @Select("SELECT COUNT(DISTINCT tag) FROM dataset_tags")
    long selectTagsCount();

    @Select("SELECT tag FROM dataset_tags " +
            "WHERE tag IS NOT NULL AND tag <> '' " +
            "GROUP BY tag " +
            "ORDER BY COUNT(*) DESC " +
            "LIMIT 8")
    List<String> selectCommonTags();
}



